package gui;

import gui.pages.*;

import javax.swing.*;
import java.awt.*;

public class MainPage extends JPanel {
    private JPanel p;

    public MainPage () {
        super(new BorderLayout());
        p = new WelcomePage();
        add(p, BorderLayout.CENTER);
        JMenuBar menuBar = new JMenuBar();
        add(menuBar, BorderLayout.NORTH);
        JMenu all = new JMenu("全部项目");
        JMenu query = new JMenu("搜索项目");
        JMenu addIn = new JMenu("添加条目");
        JMenu Earn = new JMenu("收益");
        menuBar.add(all);
        menuBar.add(query);
        menuBar.add(addIn);
        menuBar.add(Earn);
        JMenuItem b1 = new JMenuItem("已结束项目"),
                b2 = new JMenuItem("进行中项目"),
                b3 = new JMenuItem("按年份"),
                b4 = new JMenuItem("按项目名"),
                b5 = new JMenuItem("添加投资"),
                b6 = new JMenuItem("收益");
        all.add(b1);
        all.add(b2);
        query.add(b3);
        query.add(b4);
        addIn.add(b5);
        Earn.add(b6);
        b1.addActionListener(x -> update(new Page1_1()));
        b2.addActionListener(x -> update(new Page1_2()));
        b3.addActionListener(x -> update(new Page2_1()));
        b4.addActionListener(x -> update(new Page2_2()));
        b5.addActionListener(x -> update(new Page3()));
        b6.addActionListener(x -> update(new Page4()));
    }

    void update (JPanel px) {
        remove(p);
        add(px, BorderLayout.CENTER);
        p = px;
        updateUI();
    }
}
